import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('UINode')
export class UINode extends Component {
    protected onLoad(): void {
        this.tranverseChildren(this.node, node => {
            if (node.name[0] == '_')
                this[node.name] = node;
        });
    }
    tranverseChildren(root: Node, op: (node: Node) => void) {
        for (let i = 0; i < root.children.length; i++) {
            let child = root.children[i];
            op(child);
            this.tranverseChildren(child, op);
        }

    }
    protected onDestroy(): void {
        this.tranverseChildren(this.node, node => {
            if (node.name[0] == '_')
                this[node.name] = undefined;
        });

    }
}


